package com.itheima.common;

import com.itheima.dto.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Component
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public Result RuntimeExceptionHandler(RuntimeException exception){
        exception.printStackTrace();
        String message = exception.getMessage();
        return Result.error(message);
    }
}
